const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

// 提示框
export const showToast = (title,icon="none",duration=3000)=>{
  wx.showToast({
    title,
    icon,
    duration,
    mask:true
  })
}

// 加载
export const showLoading = (title)=>{
  wx.showLoading({
    title,
    mask:true
  })
}

// 模态框
export const showModal1 = (content)=>{
  return new Promise((resolve, reject)=>{
   wx.showModal({
      title:"提示",
      content,
      success:({confirm})=>{
        if(confirm) {
          resolve(confirm)
        }
      }
    })
  })
}

//网络请求
// const Url = "https://yueyun188-0gdwo4vh4afabc50-1306555544.ap-shanghai.service.tcloudbase.com/api/v1.0/"
const Url = "https://msmktest1.hfbdqn.cn/"

export const request = ({url,data={},method="get"}) =>{
  return new Promise((resolve,reject)=>{
    wx.request({
      url: `${Url}${url}`,
      data,
      method,
      success:res=>{
        resolve(res)
      },
      fail:err=>{
        reject(err)
      }
    })
  })
}

//报错提示
export const err = (content,url)=>{
  setTimeout(()=>{
    wx.showModal({
      cancelColor: 'cancelColor',
      title:'提示',
      content:content,
      showCancel:false,
      success:res=>{
       wx.switchTab({
         url: url,
       })
      }
    })
   },3000)
}

// module.exports = {
//   //es6 对象属性值和名相同可以只写一个
//   formatTime,
//   showToast
// }
